package com.tianbo.elfii.client.common;

import java.io.*;
import java.sql.* ;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.util.Timer;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
import javax.imageio.*;

import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;

/**  <pre>
     <b>类功能描述：</b><pre>
     完成 Config 功能要求。
     </pre>
     @version 1.0.1
     @author 高伟 
*/

public class ElfiiCommonConfig {

    JPanel configPanel;
    JPanel itemPanel;

    int infoBgStartX0;
    int infoBgStartY0;

    int dataChoiceIndex;

    boolean isAboutMachineSelected=false;
    boolean isSoftwareUpdateSelected=false;

    JFrame mainFrame;
    ElfiiCommonRunInfo runInfo;

    ItemButtonPanel aboutMachinePanel;
    ItemButtonPanel softwareUpdatePanel;
    ItemButtonPanel netConfigPanel;
    ItemButtonPanel sonicVolumePanel;
    ItemButtonPanel lightVolumePanel;
//    ItemButtonPanel restorePanel;
    ItemButtonPanel screenCalibrationPanel;

    final int Id_AboutMachine=1;
    final int Id_SoftwareUpdate=2;
    final int Id_NetConfig=3;
    final int Id_SonicVolume=4;
    final int Id_LightVolume=5;
    final int Id_Restore=6;
    final int Id_ScreenCalibration=7;

    int selectedId;

    JPanel mainPanel;
    
    LightVolumeWindowPanel lightVolumeWindowPanel;
    SonicVolumeWindowPanel sonicVolumeWindowPanel;
    
    CalibrationPane calibrationPane;

    int slideLightStartX0=310;
    int slideLightStartY0=393;
    int slideLightButtonX=500;
    int slideLightButtonY=393;
    int slideLightButtonMinX=310;
    int slideLightButtonMaxX=705;

    int slideSonicStartX0=310;
    int slideSonicStartY0=413;
    int slideSonicButtonX=500;
    int slideSonicButtonY=413;
    int slideSonicButtonMinX=310;
    int slideSonicButtonMaxX=705;

    public void setRunInfo(ElfiiCommonRunInfo runInfo){
        this.runInfo=runInfo;
        this.mainFrame=runInfo.getMainFrame();
    }

    public void dealBackButton(){
        mainFrame.getContentPane().removeAll();
        ElfiiCommonWelcome welcome = new ElfiiCommonWelcome();
        welcome.setRunInfo(runInfo);
        JPanel p=welcome.createViewPanel();
        mainFrame.getContentPane().setLayout(new BorderLayout());
        mainFrame.getContentPane().add(p,BorderLayout.CENTER);
        mainFrame.validate();
    }

    public void dealOkButton(){

        if (selectedId==Id_AboutMachine) {
            mainFrame.getContentPane().removeAll();
            mainFrame.getContentPane().setLayout(new BorderLayout());
            ElfiiCommonConfigAboutMachine aboutMachine = new ElfiiCommonConfigAboutMachine();
            aboutMachine.setRunInfo(runInfo);

            mainFrame.getContentPane().add(aboutMachine.createViewPanel(),BorderLayout.CENTER);
            mainFrame.validate();
        }

        if (selectedId==Id_SoftwareUpdate) {
            mainFrame.getContentPane().removeAll();
            mainFrame.getContentPane().setLayout(new BorderLayout());
            ElfiiCommonConfigUpdate update = new ElfiiCommonConfigUpdate();
            update.setRunInfo(runInfo);

            mainFrame.getContentPane().add(update.createViewPanel(),BorderLayout.CENTER);
            mainFrame.validate();
        }

        if (selectedId==Id_NetConfig) {
            mainFrame.getContentPane().removeAll();
            mainFrame.getContentPane().setLayout(new BorderLayout());
            ElfiiCommonConfigNet configItem = new ElfiiCommonConfigNet();
            configItem.setRunInfo(runInfo);

            mainFrame.getContentPane().add(configItem.createViewPanel(),BorderLayout.CENTER);
            mainFrame.validate();
        }

        if (selectedId==Id_LightVolume) {
        	lightVolumeWindowPanel.screenshot();
            mainFrame.setContentPane(lightVolumeWindowPanel);
            mainFrame.validate();
        }

        if (selectedId==Id_SonicVolume) {
        	sonicVolumeWindowPanel.screenshot();
            mainFrame.setContentPane(sonicVolumeWindowPanel);
            mainFrame.validate();
        }

        if (selectedId==Id_Restore) {
            mainFrame.getContentPane().removeAll();
            mainFrame.getContentPane().setLayout(new BorderLayout());
            ElfiiCommonConfigRestore restore = new ElfiiCommonConfigRestore();
            restore.setRunInfo(runInfo);

            mainFrame.getContentPane().add(restore.createViewPanel(),BorderLayout.CENTER);
            mainFrame.validate();
        }
        
        if(selectedId==Id_ScreenCalibration){

        	calibrationPane.screenshot();
        	calibrationPane.contentPane = mainFrame.getContentPane();
        	mainFrame.setContentPane(calibrationPane);
        	calibrationPane.showDialog();
			mainFrame.validate();
        }

    }

    class LightVolumeWindowPanel extends JPanel {

        BufferedImage infoImage;
        BufferedImage bgImg;
        BufferedImage bgImg2;

        BufferedImage lightImage;

        int rectX0=242,rectY0=220;
        int rectWidth=530,rectHeight=280;

        int brightnessTotalLen;
        int brightnessValidLen;
        int brightnessValue=0;

        public LightVolumeWindowPanel(){
            File f;
            try {
                f=new File("resource-common/images/config/icons/tb.png");
                infoImage=ImageIO.read(f);
                
                f=new File("resource-common/images/config/bg.png");
                bgImg2 = ImageIO.read(f);

                f=new File("resource-common/images/config/ss_23.png");
                lightImage=ImageIO.read(f);
                bgImg=null;
                
            } catch(Exception e) {System.out.print(e);}

            brightnessTotalLen=slideLightButtonMaxX-slideLightButtonMinX;

            try {
            	brightnessValue=ElfiiCommonConfigUtil.getBrightness();
            } catch(Exception e) {System.out.println(e);}
            slideLightButtonX=slideLightStartX0+(brightnessTotalLen*brightnessValue/15);
        }
        
        public void screenshot(){
            try {
                int x0=(int) mainFrame.getLocationOnScreen().getX();
                int y0=(int) mainFrame.getLocationOnScreen().getY();
                Robot rbt = new Robot();
                bgImg=rbt.createScreenCapture(new Rectangle(x0,y0,1024,768));
                
            } catch(Exception e) {System.out.print(e);}
        }

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
//            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));   
            g2.drawImage(bgImg,null,0,0);
            g2.drawImage(bgImg2, null, 0, 0);
//            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));   
            g2.setStroke(new BasicStroke(1.0f));

            g2.setColor(Color.white);
            g2.fillRoundRect(rectX0,rectY0,rectWidth,rectHeight,10,10);
            g2.setColor(Color.black);
            g2.fillRoundRect(rectX0+5,rectY0+5,rectWidth-10,rectHeight-10,10,10);
            g2.drawImage(infoImage,null,rectX0+30,rectY0+20);
            g2.setColor(Color.gray);
            g2.drawLine(rectX0+20,rectY0+85,rectX0+rectWidth-20,rectY0+85);
            g2.fillRect(rectX0+5,rectY0+rectHeight-55,rectWidth-10,50);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,30));
            g2.setColor(Color.white);
            g2.drawString("亮度",rectX0+105,rectY0+60);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
            g2.drawString("调节屏幕显示亮度",rectX0+110,rectY0+120);

            g2.drawImage(lightImage,null,rectX0+33,rectY0+143);
            g2.drawLine(slideLightButtonMinX,rectY0+155,slideLightButtonMaxX,rectY0+155);

            g2.setColor(ElfiiCommonConstant.Elfii_Blue);

            g2.setStroke(new BasicStroke(5.0f));

            g2.drawLine(slideLightStartX0,slideLightStartY0-18,slideLightButtonX,slideLightButtonY-18);
            g2.fillOval(slideLightButtonX-3,slideLightButtonY-25,15,15);

        }
        public Dimension getPreferredSize() {
            return (new Dimension(300,100));
        }
    }

    public void dealLightWindowMouseDragged(MouseEvent e){
        int x=e.getX();
        int y=e.getY();
        if (y>slideLightButtonY-20 && y<slideLightButtonY+20) {
            slideLightButtonX=x;
            if (slideLightButtonX>slideLightButtonMaxX)
                slideLightButtonX=slideLightButtonMaxX;
            if (slideLightButtonX<slideLightButtonMinX)
                slideLightButtonX=slideLightButtonMinX;
            lightVolumeWindowPanel.repaint();
            int a1=(slideLightButtonX-slideLightStartX0);
            int a2=(slideLightButtonMaxX-slideLightButtonMinX);
            double d=(a1+0.0001)/(a2+0.0001)*15.00;
            int brightnessPercent=(int) d;
            ElfiiCommonConfigUtil.setBrightness(brightnessPercent);
        }
    }

    public void dealLightWindowMousePressed(MouseEvent e){
    	
        int x=e.getX();
        int y=e.getY();
        //System.out.println("clicked x="+x+"   x0="+slideLightStartX0);

        if (y>slideLightButtonY-20 && y<slideLightButtonY+20) {
            slideLightButtonX=x;
            if (slideLightButtonX>slideLightButtonMaxX)
                slideLightButtonX=slideLightButtonMaxX;
            if (slideLightButtonX<slideLightButtonMinX)
                slideLightButtonX=slideLightButtonMinX;
            lightVolumeWindowPanel.repaint();
            
            int a1=(slideLightButtonX-slideLightStartX0);
            int a2=(slideLightButtonMaxX-slideLightButtonMinX);
            double d=(a1+0.0001)/(a2+0.0001)*15.00;
            int brightnessPercent=(int) d;
            ElfiiCommonConfigUtil.setBrightness(brightnessPercent);
        }
    }

    class SonicVolumeWindowPanel extends JPanel {

        BufferedImage infoImage;
        BufferedImage bgImg;
        BufferedImage sonicImage;
        BufferedImage bgImg2;

        int volumeTotalLen;
        int volumeValidLen;
        int volumeValue=0;

        int rectX0=242,rectY0=220;
        int rectWidth=530,rectHeight=280;

        public SonicVolumeWindowPanel(){
            File f;
            try {
                f=new File("resource-common/images/config/icons/tb.png");
                infoImage=ImageIO.read(f);

                f=new File("resource-common/images/config/bg.png");
                bgImg2 = ImageIO.read(f);
                
                f=new File("resource-common/images/config/ss_08.png");
                sonicImage=ImageIO.read(f);
                
                bgImg = null;
            } catch(Exception e) {System.out.print(e);}

            volumeTotalLen=slideSonicButtonMaxX-slideSonicButtonMinX;
            try {
                volumeValue=ElfiiCommonConfigUtil.getSoundVolume();
            } catch(Exception e) {System.out.println(e);}
            slideSonicButtonX=slideSonicStartX0+(volumeTotalLen*volumeValue/100);
        }
        
        public void screenshot(){
            try {
                int x0=(int) mainFrame.getLocationOnScreen().getX();
                int y0=(int) mainFrame.getLocationOnScreen().getY();
                Robot rbt = new Robot();
                bgImg=rbt.createScreenCapture(new Rectangle(x0,y0,1024,768));
                
            } catch(Exception e) {System.out.print(e);}
        }

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
//            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));   
            g2.drawImage(bgImg,null,0,0);
//            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));   

            g2.drawImage(bgImg2, null, 0, 0);
            
//            int rectX0=242,rectY0=220;
//            int rectWidth=530,rectHeight=280;
            g2.setStroke(new BasicStroke(1.0f));

            g2.setColor(Color.white);
            g2.fillRoundRect(rectX0,rectY0,rectWidth,rectHeight,10,10);
            g2.setColor(Color.black);
            g2.fillRoundRect(rectX0+5,rectY0+5,rectWidth-10,rectHeight-10,10,10);
            g2.drawImage(infoImage,null,rectX0+30,rectY0+20);
            g2.setColor(Color.gray);
            g2.drawLine(rectX0+20,rectY0+85,rectX0+rectWidth-20,rectY0+85);
            g2.fillRect(rectX0+5,rectY0+rectHeight-55,rectWidth-10,50);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,30));
            g2.setColor(Color.white);
            g2.drawString("声音",rectX0+105,rectY0+60);
            
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,18));
            g2.drawString("音效",rectX0+30,rectY0+132);
            
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
            g2.drawString("开启",rectX0+190,rectY0+133);
            
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
            g2.drawString("关闭",rectX0+350,rectY0+133);
            

            g2.drawImage(sonicImage,null,rectX0+35,rectY0+165);
            g2.drawLine(slideSonicButtonMinX,rectY0+175,slideSonicButtonMaxX,rectY0+175);

            g2.setColor(ElfiiCommonConstant.Elfii_Blue);
            g2.setStroke(new BasicStroke(5.0f));

            g2.drawLine(slideSonicStartX0,slideSonicStartY0-18,slideSonicButtonX,slideSonicButtonY-18);
            g2.fillOval(slideSonicButtonX-2,slideSonicButtonY-25,15,15);

        }
        public Dimension getPreferredSize() {
            return (new Dimension(300,100));
        }
    }

    public void dealSonicWindowMouseDragged(MouseEvent e){
        int x=e.getX();
        int y=e.getY();
        if (y>slideSonicButtonY-20 && y<slideSonicButtonY+20) {
            slideSonicButtonX=x;
            if (slideSonicButtonX>slideSonicButtonMaxX)
                slideSonicButtonX=slideSonicButtonMaxX;
            if (slideSonicButtonX<slideSonicButtonMinX)
                slideSonicButtonX=slideSonicButtonMinX;
            sonicVolumeWindowPanel.repaint();
            int a1=(slideSonicButtonX-slideSonicStartX0);
            int a2=(slideSonicButtonMaxX-slideSonicButtonMinX);
            double d=(a1+0.0001)/(a2+0.0001)*100.00;
            int volumePercent=(int) d;
            ElfiiCommonConfigUtil.setSoundVolume(volumePercent);
        }
    }

    public void dealSonicWindowMousePressed(MouseEvent e){
        int x=e.getX();
        int y=e.getY();
        //System.out.println("clicked x="+x+"   x0="+slideSonicStartX0);

        if (y>slideSonicButtonY-20 && y<slideSonicButtonY+20) {
            slideSonicButtonX=x;
            if (slideSonicButtonX>slideSonicButtonMaxX)
                slideSonicButtonX=slideSonicButtonMaxX;
            if (slideSonicButtonX<slideSonicButtonMinX)
                slideSonicButtonX=slideSonicButtonMinX;
            sonicVolumeWindowPanel.repaint();
            
            int a1=(slideSonicButtonX-slideSonicStartX0);
            int a2=(slideSonicButtonMaxX-slideSonicButtonMinX);
            double d=(a1+0.0001)/(a2+0.0001)*100.00;
            int volumePercent=(int) d;
            ElfiiCommonConfigUtil.setSoundVolume(volumePercent);
        }
    }


    public void createConfigPanel(){

        JButton settingsButton=new JButton("设置");
        settingsButton.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,15));
        settingsButton.setBackground(Color.gray);
        settingsButton.setForeground(Color.white);
        settingsButton.setBorderPainted(false);
        settingsButton.setFocusPainted(false);
        settingsButton.setHorizontalAlignment(SwingConstants.LEFT);
        settingsButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;

        aboutMachinePanel=new ItemButtonPanel("b_01.png","bn_01.png","关于本机","名称、版本号、型号、序列号、网卡地址、WiFi地址、法律声明、许可证信息");
        aboutMachinePanel.setFocusable(true);
        aboutMachinePanel.setBackground(Color.black);
        aboutMachinePanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_AboutMachine);
                }
            }
            );

        softwareUpdatePanel=new ItemButtonPanel("b_02.png","bn_02.png","软件更新","软件版本信息V20.11 （最高版本V20.14,可升级到最新版本）");
        softwareUpdatePanel.setFocusable(true);
        softwareUpdatePanel.setBackground(Color.black);
        softwareUpdatePanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_SoftwareUpdate);
                }
            }
            );

        netConfigPanel=new ItemButtonPanel("b_03.png","bn_03.png","网络配置","WLAN连接、VLAN设置、WIFI连接、WIFI设置、HTTP代理");
        netConfigPanel.setFocusable(true);
        netConfigPanel.setBackground(Color.black);
        netConfigPanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_NetConfig);
                }
            }
            );

        sonicVolumePanel=new ItemButtonPanel("b_04.png","bn_04.png","音量","设置音量调节信息");
        sonicVolumePanel.setFocusable(true);
        sonicVolumePanel.setBackground(Color.black);
        sonicVolumePanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_SonicVolume);
                }
            }
            );

        lightVolumePanel=new ItemButtonPanel("b_05.png","bn_05.png","亮度","设置屏幕亮度调节信息");
        lightVolumePanel.setFocusable(true);
        lightVolumePanel.setBackground(Color.black);
        lightVolumePanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_LightVolume);
                }
            }
            );

//        restorePanel=new ItemButtonPanel("bn_06.png","b_06.png","系统还原","还原数据信息、还原系统配置信息");
//        restorePanel.setFocusable(true);
//        restorePanel.setBackground(Color.black);
//        restorePanel.addMouseListener(new MouseAdapter(){
//                public void mousePressed(MouseEvent e) {
//                    setSelectButton(Id_Restore);
//                }
//            }
//            );

        screenCalibrationPanel=new ItemButtonPanel("b_07.png","bn_07.png","屏幕校准","屏幕校准");
        screenCalibrationPanel.setFocusable(true);
        screenCalibrationPanel.setBackground(Color.black);
        screenCalibrationPanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    setSelectButton(Id_ScreenCalibration);
                }
            }
            );

        configPanel=new JPanel();
        configPanel.setBackground(Color.black);
        configPanel.setLayout(null);

        configPanel.add(settingsButton);
        settingsButton.setBounds(0,10,1024,25);

        configPanel.add(aboutMachinePanel);
        aboutMachinePanel.setBounds(0,45,1024,75);
        configPanel.add(softwareUpdatePanel);
        softwareUpdatePanel.setBounds(0,120,1024,75);
        configPanel.add(netConfigPanel);
        netConfigPanel.setBounds(0,195,1024,75);
        configPanel.add(sonicVolumePanel);
        sonicVolumePanel.setBounds(0,270,1024,75);
        configPanel.add(lightVolumePanel);
        lightVolumePanel.setBounds(0,345,1024,75);
//        configPanel.add(restorePanel);
//        restorePanel.setBounds(0,420,1024,75);
        configPanel.add(screenCalibrationPanel);
        screenCalibrationPanel.setBounds(0,420,1024,75);
    }

    public void setSelectButton(int selectedId){
    	
    	if(this.selectedId==selectedId){
    		return;
    	}
    	
    	
    	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
    	
        this.selectedId=selectedId;
        aboutMachinePanel.setSelected(false);
        softwareUpdatePanel.setSelected(false);
        netConfigPanel.setSelected(false);
        sonicVolumePanel.setSelected(false);
        lightVolumePanel.setSelected(false);
//        restorePanel.setSelected(false);
        screenCalibrationPanel.setSelected(false);
        if (selectedId==Id_AboutMachine)
            aboutMachinePanel.setSelected(true);
        if (selectedId==Id_SoftwareUpdate)
            softwareUpdatePanel.setSelected(true);
        if (selectedId==Id_NetConfig)
            netConfigPanel.setSelected(true);
        if (selectedId==Id_SonicVolume)
            sonicVolumePanel.setSelected(true);
        if (selectedId==Id_LightVolume)
            lightVolumePanel.setSelected(true);
//        if (selectedId==Id_Restore)
//            restorePanel.setSelected(true);
        if (selectedId==Id_ScreenCalibration)
            screenCalibrationPanel.setSelected(true);
    }

    class ItemButtonPanel extends JPanel {
        BufferedImage unSelectedImage;
        BufferedImage selectedImage;
        BufferedImage selectedBgImage;

        BufferedImage lineImage;

        BufferedImage img2;

        BufferedImage gaoImg;

        String str1;
        String str2;
        boolean isSelected;
        public ItemButtonPanel(String unSelectedImageFile,
                               String selectedImageFile,
                               String str1,
                               String str2) {
            this.str1=str1;
            this.str2=str2;
            File f=null;
            try {
                f=new File("resource-common/images/config/icons/"+unSelectedImageFile);
                unSelectedImage=ImageIO.read(f);
                f=new File("resource-common/images/config/icons/"+selectedImageFile);
                selectedImage=ImageIO.read(f);
                f=new File("resource-common/images/config/icons/tc_butbg.png");
                selectedBgImage=ImageIO.read(f);
                f=new File("resource-common/images/config/icons/tb_bg.png");
                img2=ImageIO.read(f);
                f=new File("resource-common/images/config/icons/line.png");
                lineImage=ImageIO.read(f);
            } catch(Exception e) {System.out.print(e+"   "+f);}
        }

        public void setSelected(boolean isSelected){
            this.isSelected=isSelected;
            repaint();
        }

        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g ;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
            g2.setColor(Color.black);
            g2.fillRect(0,0,1024,58);

            if (isSelected) {
                g2.drawImage(selectedBgImage,null,0,0);
                //g2.drawImage(img2,null,0,0);
                g2.drawImage(selectedImage,null,10,10);
                g2.setColor(ElfiiCommonConstant.Elfii_Blue);
            }else{
                g2.drawImage(img2,null,10,10);
                g2.drawImage(unSelectedImage,null,10,10);
                g2.setColor(Color.white);
            }

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,20));
            g2.drawString(str1,90,35);  
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,14));
            g2.drawString(str2,90,58);  
            g2.drawImage(lineImage,null,0,74);
        }

        public Dimension getPreferredSize() {
            return (new Dimension(1024,66));
        }
    }

    public JPanel createViewPanel(){
        mainPanel = new JPanel(new BorderLayout()) ;
        JButton okButton=new JButton();
        okButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealOkButton();
                    if(selectedId>0)
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });

        JButton backButton=new JButton();
        backButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dealBackButton();
                    ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                }
            });

        JButton homeButton=runInfo.createHomeButton();
        JPanel topPanel=ElfiiCommonUtil.createTopPanel("系统设置",backButton,homeButton);
        JPanel bottomPanel=ElfiiCommonUtil.createBottomPanelLevelSelect(okButton);
        createConfigPanel();
        mainPanel.setLayout(null);
        mainPanel.setBackground(Color.black);
        mainPanel.add(topPanel);
        topPanel.setBounds(0,0,1024,100);
        mainPanel.add(bottomPanel);
        bottomPanel.setBounds(0,668,1024,100);
        mainPanel.add(configPanel);
        configPanel.setBounds(0,101,1024,560);

		Timer timer = new Timer();
		
		timer.schedule(new TimerTask(){
			public void run() {
				// TODO Auto-generated method stub
				initNextPanel();
			}
		}, 100);
		

		return mainPanel;
	}
	
	public void initNextPanel(){
		initVolumeWindowPanel();
		initBrigtnessWindowPanel();

    	calibrationPane = new CalibrationPane(4);
	}
	
	public void initVolumeWindowPanel(){
        JButton sonicVolumeYesButton=new JButton();
        
        ImageIcon confirmIcon = new ImageIcon("resource-common/images/login/sssss06.png","");
        sonicVolumeYesButton.setBackground(Color.white);
        sonicVolumeYesButton.setBorderPainted(false);
        sonicVolumeYesButton.setFocusPainted(false);
        sonicVolumeYesButton.setIcon(confirmIcon);
        sonicVolumeYesButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                	mainFrame.setContentPane(mainPanel);
                	mainFrame.validate();
                }
            });

        sonicVolumeYesButton.setBackground(Color.darkGray);
        sonicVolumeYesButton.setContentAreaFilled(false);
        

        JRadioButton audioEffectOn = new JRadioButton();
        JRadioButton audioEffectOff = new JRadioButton();
        

        ImageIcon unSelectedIcon = new ImageIcon("resource-common/images/level 04.png");
        ImageIcon selectedIcon = new ImageIcon("resource-common/images/level 05.png");
        
        audioEffectOn.setIcon(unSelectedIcon);
        audioEffectOn.setSelectedIcon(selectedIcon);
        audioEffectOn.setContentAreaFilled(false);

        
        audioEffectOff.setIcon(unSelectedIcon);
        audioEffectOff.setSelectedIcon(selectedIcon);
        audioEffectOff.setContentAreaFilled(false);
        
        ButtonGroup group = new ButtonGroup();
        group.add(audioEffectOn);
        group.add(audioEffectOff);
        
        if(ElfiiCommonConfigUtil.isAudioEffectOn){
        	audioEffectOn.setSelected(true);
        }
        else{
        	audioEffectOff.setSelected(true);
        }
        
        
        audioEffectOn.addItemListener(new ItemListener(){
        	 public void itemStateChanged(ItemEvent e) {
        		 JRadioButton jop=(JRadioButton) e.getSource();
        		 
        		 if(jop.isSelected()){

                  	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                  	
        			ElfiiCommonConfigUtil.isAudioEffectOn = true;
        			 
                 	Statement st = runInfo.getStatement1();
                 	String str = "UPDATE systemconfig SET isaudioeffect='1' WHERE id='0'";
                 	try {
						st.execute(str);
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
                 	
                 	
        		 }
        	 }
        });
        
        audioEffectOff.addItemListener(new ItemListener(){
       	 public void itemStateChanged(ItemEvent e) {
       		 JRadioButton jop=(JRadioButton) e.getSource();
       		 
       		 if(jop.isSelected()){
       			 

             	
             	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
             	
       			ElfiiCommonConfigUtil.isAudioEffectOn = false;
       			
                	Statement st = runInfo.getStatement1();
                	String str = "UPDATE systemconfig SET isaudioeffect='0' WHERE id='0'";
                	try {
						st.execute(str);
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
       		 }
       	 }
       });

        sonicVolumeWindowPanel= new SonicVolumeWindowPanel();
        sonicVolumeWindowPanel.setLayout(null);
        sonicVolumeWindowPanel.add(sonicVolumeYesButton);
        sonicVolumeYesButton.setBounds(452,450,121,43);
        
        sonicVolumeWindowPanel.add(audioEffectOn);
        audioEffectOn.setBounds(400, 335, 100, 25);
        
        sonicVolumeWindowPanel.add(audioEffectOff);
        audioEffectOff.setBounds(550, 335, 100, 25);

        sonicVolumeWindowPanel.setBounds(0,0,1024,768);

        sonicVolumeWindowPanel.setFocusable(true);
        sonicVolumeWindowPanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    dealSonicWindowMousePressed(e);
                }
            }
            );
        sonicVolumeWindowPanel.addMouseMotionListener(new MouseAdapter(){
                public void mouseDragged(MouseEvent e) {
                    dealSonicWindowMouseDragged(e);
                }
            }
            );
	}
	
	public void initBrigtnessWindowPanel(){

        JButton lightVolumeYesButton=new JButton();
        ImageIcon backIcon = new ImageIcon("resource-common/images/login/sssss06.png","");
        lightVolumeYesButton.setBackground(Color.white);
        lightVolumeYesButton.setBorderPainted(false);
        lightVolumeYesButton.setFocusPainted(false);
        lightVolumeYesButton.setIcon(backIcon);
        lightVolumeYesButton.addActionListener( new ActionListener() {
                public void actionPerformed(ActionEvent e) {
//                    lightVolumeWindow.dispose();
                	ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
                	mainFrame.setContentPane(mainPanel);
                	mainFrame.validate();
                }
            });

        lightVolumeYesButton.setBackground(Color.darkGray);
        lightVolumeYesButton.setContentAreaFilled(false);


        lightVolumeWindowPanel= new LightVolumeWindowPanel();
        lightVolumeWindowPanel.setLayout(null);
        lightVolumeWindowPanel.add(lightVolumeYesButton);
        lightVolumeYesButton.setBounds(452,450,121,43);
        lightVolumeWindowPanel.setBounds(0,0,1024,768);

        lightVolumeWindowPanel.setFocusable(true);
        lightVolumeWindowPanel.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e) {
                    dealLightWindowMousePressed(e);
                }
            }
            );
        lightVolumeWindowPanel.addMouseMotionListener(new MouseAdapter(){
                public void mouseDragged(MouseEvent e) {
                    dealLightWindowMouseDragged(e);
                }
            }
            );
	}

}
